<template>
  <div class="wrapper-right">
    <div class="title-box">
      <Title title="当日现场人气榜（全市）" style="color: #e4393c;" />
      <i class="iconfont icon-show_renqiredu"></i>
    </div>

    <el-table :data="tableData" height="94%" style="width: 100%" ref="tableRef">
      <el-table-column prop="branch" label="营业部" width="120" align="center" show-overflow-tooltip></el-table-column>
      <el-table-column prop="community" label="小区" width="auto" align="center" show-overflow-tooltip></el-table-column>
      <el-table-column prop="assessment" label="人气" width="95" align="center">
        <template slot-scope="scope">
          <el-rate v-model="scope.row.assessment" disabled :colors="['#e4393c','#e4393c','#e4393c']" disabled-void-color="#c8c8c8"></el-rate>
        </template>
      </el-table-column>
      <el-table-column prop="process" label="场景" width="70" align="center">
        <template slot-scope="scope">
          <div v-if="scope.row.process == '1'">
            <el-tag type="success">好</el-tag>
          </div>
          <div v-if="scope.row.process == '2'">
            <el-tag type="warning">一般</el-tag>
          </div>
          <div v-if="scope.row.process == '3'">
            <el-tag type="danger">差</el-tag>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
  import { countByRanking } from "@/api/home";
  import { getDeptTree } from "@/api/system/user";
  import { popular } from "@/api/api";
  import Title from "./Title";
  import store from "@/store";
  export default {
    name: "HomeRight",
    components: { Title },
    data() {
      return {
        postData: 
          {
            // deptId: 219,
            deptId: store.state.user.deptId, //将缓存的用户id赋值给userId，用于查询营销人员
          },

        //小区业务数据统计排名
        tableData: [
          {
            branch: "十里店营业部",
            community: "城关区天庆嘉园B区",
            assessment: 4.5,
            process: "1",
          },
          {
            branch: "十里店营业部",
            community: "城关区天庆嘉园B区",
            assessment: 5,
            process: "2",
          },
          {
            branch: "十里店营业部",
            community: "城关区天庆嘉园B区",
            assessment: 4.1,
            process: "3",
          },
          {
            branch: "十里店营业部",
            community: "城关区天庆嘉园B区",
            assessment: 3.6,
            process: "2",
          },
          {
            branch: "十里店营业部",
            community: "城关区天庆嘉园B区",
            assessment: 3,
            process: "2",
          },
          {
            branch: "十里店营业部",
            community: "城关区天庆嘉园B区",
            assessment: 1.5,
            process: "1",
          },
          {
            branch: "十里店营业部",
            community: "城关区天庆嘉园B区",
            assessment: 3,
            process: "1",
          },
          {
            branch: "十里店营业部",
            community: "城关区天庆嘉园B区",
            assessment: 5,
            process: "1",
          },
          {
            branch: "十里店营业部",
            community: "城关区天庆嘉园B区",
            assessment: 4,
            process: "1",
          },
          {
            branch: "十里店营业部",
            community: "城关区天庆嘉园B区",
            assessment: 2,
            process: "1",
          },
          {
            branch: "十里店营业部",
            community: "城关区天庆嘉园B区",
            assessment: 4,
            process: "1",
          },
          {
            branch: "十里店营业部",
            community: "城关区天庆嘉园B区",
            assessment: 5,
            process: "1",
          },
          {
            branch: "十里店营业部",
            community: "城关区天庆嘉园B区",
            assessment: 1,
            process: "1",
          },
          
        ],
      };
    },
    created() {
      // this.getDeptTree(100);
      // this.countByRanking({ deptId: 100 });
      // this.getPopular()
    },
    methods: {
      getPopular() { 
        popular().then(res => { 
          res.forEach((item,index) => { 
            this.tableData[index].process = this.getStarRating(item.popAssess);
          });
          // this.tableData = res;
        })
      },

      getStarRating(popAssess) {
        if (popAssess >= 20) {
          return 5;   // 20张以上：5颗星
        } else if (popAssess >= 15) {
          return 4;   // 15-20张：四颗星（含15张）
        } else if (popAssess >= 10) {
          return 3;   // 10-14张：三颗星
        } else if (popAssess >= 5) {
          return 2;   // 5-9张：两颗星
        } else {
          return 1;   // 0-4张：一颗星
        }
      },
    /** 查询部门下拉树结构 */
    async getDeptTree(deptId) {
        getDeptTree({ deptId: deptId }).then((response) => {
          var treeData = response.data.children;

          if (deptId == 100) {
            this.salesDepartmentList = [
              {
                deptName: response.data.deptName,
                deptId: response.data.deptId,
              },
              {
                deptName: response.data.children[0].deptName,
                deptId: response.data.children[0].deptId,
              },
              {
                deptName: response.data.children[1].deptName,
                deptId: response.data.children[1].deptId,
              },
            ];

            console.log(this.salesDepartmentList, "树结构");
            // this.deptOptions = treeData;
          } else {
            this.baoQuListR = response.data.children;
          }
        });
      },
      countByRanking(data) {
        countByRanking(data).then((response) => {
          console.log(response.data, "小区业务数据统计排名");
          response.data.sort((a, b) => {
            return (
              b.percent.substring(0, b.percent.length - 1) -
              a.percent.substring(0, a.percent.length - 1)
            );
          });
          response.data.forEach((item, index) => {
            /*  this.tableData.push({
              rank: index + 1,
              community: item.deptName,
              accomplish: item.percent,
              isOk: item.finished,
           }); */
          });
        });
      },
      //时间切换
      handleCommunityTime() {
        this.$message("数据完善中...");
      },
      //包区数据选中
      handleCommunityBusinessBaoquChange(value) {
        this.tableData = [];
        this.countByRanking({ deptId: value });
      },
      //小区业务数据统计排名
      handleCommunityBusinessChange(value) {
        this.baoQuListR = [];
        this.tableData = [];
        this.communityBusiness.baoQu = "";
        this.postData.deptId = value;
        this.countByRanking({ deptId: value });
        this.getDeptTree(value);
      },
      getRanking(rank) {
        if (rank == "1") {
          return "first";
        } else if (rank == "2") {
          return "second";
        } else if (rank == "3") {
          return "third";
        } else {
          return "other";
        }
      },
    },
  };
</script>

<style scoped lang="scss">
  //@import url("//at.alicdn.com/t/c/font_4986911_ojvidgxtjmo.css");
  @import url("../../assets//fonts/iconfont.css");

  .wrapper-right {
    width: 100%;
    height: 100%;

    .title-box {
      display: flex;
      justify-content: center;
      align-items: center;
      color: #e4393c;

      i {
        font-size: 20px;
        margin-bottom: 16px;
      }
    }
  }

  .filtr-selects {
    display: flex;
    justify-content: end;
  }

  .filter-selects-righttop {
    position: absolute;
    top: -2px;
    right: -5px;
    width: 56%;

    .bottom-selects {
      width: 33%;
    }
  }

  .first {
    color: #fff;
    background-color: #fd4f4f;
    /* 红色背景 */
  }

  .second {
    color: #fff;
    background-color: #fcca00;
    /* 黄色背景 */
  }

  .third {
    color: #fff;
    background-color: #a2ef4d;
    /* 绿色背景 */
  }

  .other {
    color: #fff;
    background-color: #cecece;
    /* 灰色背景 */
  }

  .isOk-yes {
    display: flex;
    align-items: center;
    justify-content: center;

    img {
      width: 16px;
      height: 16px;
      margin-left: 5px;
    }
  }

  .isOk-no {
    display: flex;
    align-items: center;
    justify-content: center;

    img {
      width: 16px;
      height: 16px;
      margin-left: 5px;
    }
  }

  ::v-deep .el-table td.el-table__cell div {
    display: flex;
    justify-content: center;
  }

  ::v-deep .el-rate__icon {
    margin-right: 0;
  }

  ::v-deep .el-rate__item.is-disabled .el-rate__icon {
    color: #ff0000 !important;
  }


  /* ::v-deep .el-table tr { */
    /* background-color: rgba(228 57 60 / 0.1) !important; */
    /* color: #e4393c !important; */
  /* } */
</style>
